﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QuickExcel
{
    public partial class resizeChart : Form
    {
        public resizeChart()
        {
            InitializeComponent();
        }

        private void cmdClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void resizeChart_Load(object sender, EventArgs e)
        {
            if (Globals.ThisAddIn.Application.ActiveChart == null)
            {
                System.Windows.Forms.MessageBox.Show("Please select the chart and Try Again");
                this.Close();
            }

            else
            {
                txtWidth.Text = Globals.ThisAddIn.Application.ActiveChart.ChartArea.Width.ToString();
                txtHeight.Text = Globals.ThisAddIn.Application.ActiveChart.ChartArea.Height.ToString();
            }
        }

        private void cmdApply_Click(object sender, EventArgs e)
        {
            Globals.ThisAddIn.Application.ActiveChart.ChartArea.Width= Convert.ToDouble(txtWidth.Text);
            Globals.ThisAddIn.Application.ActiveChart.ChartArea.Height=Convert.ToDouble(txtHeight.Text);

            this.Close();
        }

        private void txtWidth_Leave(object sender, EventArgs e)
        {
            if (chkAspectRatio.Checked)
                txtHeight.Text = Math.Round((Convert.ToDouble(txtHeight.Text) * (Convert.ToDouble(txtWidth.Text) / Globals.ThisAddIn.Application.ActiveChart.ChartArea.Width)), 2).ToString();
        }

        private void txtHeight_Leave(object sender, EventArgs e)
        {
            if (chkAspectRatio.Checked)
                txtWidth.Text = Math.Round((Convert.ToDouble(txtWidth.Text) * (Convert.ToDouble(txtHeight.Text) / Globals.ThisAddIn.Application.ActiveChart.ChartArea.Height)), 2).ToString();
        }
    }
}
